import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css
import request from './utils/request'
Vue.prototype.$request = request
import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
// import { imgError, color } from '@/directives/index'
import * as directives from '@/directives'
// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)
// 自定义指令
// Vue.directive('imgError', imgError)
// Vue.directive('color', color)
Object.keys(directives).forEach(key => {
  Vue.directive(key, directives[key])
})
Vue.config.productionTip = false
// 定义全局的自定义指令
// Vue.directive('imgerror', {
//   // el 指令所在的元素
//   // binding 指令的相关信息对象, binding.value 指令的值
//   inserted(el, bindings) {
//     // console.log(el, bindings)
//     el.onerror = function() {
//       // console.log('图片加载失败了'), 设置备用图片地址
//       el.src = bindings.value
//     }
//   }
// })

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
